package org.jeecg.modules.baseData.onlineEnhance;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.baseData.entity.WuLianWangKa;
import org.jeecg.modules.baseData.service.IWuLianWangKaService;
import org.jeecg.modules.online.cgform.enhance.CgformEnhanceJavaInter;
import org.jeecg.modules.online.config.exception.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author wangfupeng   info
 * @date 9:40 02 02 2021
 * @Description
 * @Modified
 */

/**
 * 物联网卡导入去重
 */
@Slf4j
@Component("wuLianWangKaEnhanceImport")
public class WuLianWangKaEnhanceImport implements CgformEnhanceJavaInter {

    @Autowired
    private IWuLianWangKaService tbWuLianWangKaService;



    @Override
    public int execute(String s, JSONObject jsonObject) throws BusinessException {
        String no = jsonObject.getString("iccid");
        /**
         * 如果没有SN字段则不执行插入
         */
        if (StrUtil.isEmpty(no)) {
            return 0;
        }
        WuLianWangKa wuLianWangKa = tbWuLianWangKaService.getOneByNo(no);
        if (wuLianWangKa ==null) {
            return 1;
        }else {
            log.info("存在"+ wuLianWangKa.getIccid()+";不再插入");
            return 0;

        }

    }

    /**
     * @param s
     * @param map
     * @deprecated
     */
    @Override
    public int execute(String s, Map<String, Object> map) throws BusinessException {
        return 1;
    }

}
